home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_333 / multiplot / source / mplot_src / gethowto.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  15KB  |  525 lines

  1. #include <stdio.h>
  2. #include <exec/types.h>
  3. #include "struct.h"
  4. #include "plot.h"
  5. #include "howto1.h"
  6. #include "howto2.h"
  7.  
  8. extern char *gets();
  9. extern char *getwrd();
  10. extern struct Window *FrontWindow;
  11. extern struct Screen *screen;
  12.  
  13. extern struct NewWindow NewFrontWindow;
  14. extern struct RastPort *p;
  15. extern struct ViewPort *vp;
  16.  
  17. extern int debug;
  18.  
  19. #define LINEPLOT 0
  20. #define POINTPLOT 1
  21. #define BOTHPLOT 2
  22.  
  23. USHORT PlotType;
  24. USHORT PointType;
  25. USHORT Colour;
  26. USHORT PlotPrefs;
  27. USHORT SkipPlot;
  28. USHORT StopPlot;
  29.  
  30.  
  31. #define DEFAULT 0
  32. #define CHOOSE 1
  33. #define STOP 0
  34. #define GO 1
  35.  
  36. extern int QuitFrontFlag;
  37. short firstcall = TRUE;
  38.  
  39.  
  40. void GetHowTo(Pict)
  41. struct Pict *Pict;
  42. {
  43.    short i,j;
  44.    struct Plot *Plot;
  45.    struct IntuiMessage  *p_message;         /* pointer to message */
  46.    void ProcHowMes(), ProcCustMes(), GadMXSel();
  47.    SHORT border[] ={
  48.                    336, 76,
  49.                    400, 76,
  50.                    400,140,
  51.                    336,140,
  52.                    336, 76
  53.                  };
  54.  
  55.    QuitFrontFlag=GO;
  56.  
  57.    if (firstcall) {
  58.       firstcall = FALSE;
  59.       /*** ESTABLISH DEFAULTS ***/
  60.       PlotType=LINEPLOT;
  61.       PointType=6;
  62.       Pict->Grid = FALSE;
  63.       Pict->ShowErr = Pict->ErrBar;
  64.       Pict->Tics->NX = Pict->Tics->NY = 5;
  65.    }
  66.  
  67.    PlotPrefs=DEFAULT;
  68.    Colour=DEFAULT;
  69.    Gadget45.GadgetRender = (APTR)&Colour1;
  70.    Gadget18.Flags=(GADGHIMAGE+GADGIMAGE);
  71.  
  72.  
  73.    if (Pict->Grid == TRUE) Gadget15.Flags=(GADGHIMAGE+SELECTED+GADGIMAGE);
  74.    else Gadget15.Flags=(GADGHIMAGE+GADGIMAGE);
  75.  
  76.    if (PlotType == POINTPLOT) Gadget16.GadgetRender = (APTR)&Image6b;
  77.    else if (PlotType == BOTHPLOT) Gadget16.GadgetRender = (APTR)&Image6c;
  78.    else Gadget16.GadgetRender = (APTR)&Image6a;
  79.  
  80.    if (Pict->ErrBar==FALSE) Gadget14.Flags=(GADGHIMAGE+SELECTED+GADGDISABLED+GADGIMAGE);
  81.    else if (Pict->ShowErr==FALSE) Gadget14.Flags=(GADGHIMAGE+SELECTED+GADGIMAGE);
  82.    else Gadget14.Flags=(GADGHIMAGE+GADGIMAGE);
  83.  
  84.    NewFrontWindow.Title = title0;
  85.    NewFrontWindow.FirstGadget = &Gadget13;
  86.    NewFrontWindow.Screen = screen;
  87.    if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
  88.      {
  89.          ErrorAlert(0);
  90.          CloseScreen(screen);
  91.          sexit(FALSE);
  92.      }
  93.    p = FrontWindow->RPort;
  94.    PrintIText(p,&IText11,0,0);
  95.  
  96.   while (QuitFrontFlag !=STOP)
  97.     {
  98.        Wait(1l<<FrontWindow->UserPort->mp_SigBit);        /* wait for a message */
  99.        while (p_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
  100.          ProcHowMes(p_message,Pict);
  101.      }
  102.  
  103.    CloseWindow(FrontWindow);
  104.    if (Gadget17SInfo.LongInt<1)     /* Number of X Ticks */
  105.       {
  106.          Gadget17SInfo.LongInt=1;
  107.          strcpy(Gadget17SIBuff,"1");
  108.       }
  109.    if (Gadget17SInfo.LongInt>20)
  110.       {
  111.          Gadget17SInfo.LongInt=20;
  112.          strcpy(Gadget17SIBuff,"20");
  113.       }
  114.    if (Gadget17aSInfo.LongInt<1)          /* Number of Y Ticks */
  115.       {
  116.          Gadget17aSInfo.LongInt=1;
  117.          strcpy(Gadget17aSIBuff,"1");
  118.       }
  119.    if (Gadget17aSInfo.LongInt>20)
  120.       {
  121.          Gadget17aSInfo.LongInt=20;
  122.          strcpy(Gadget17aSIBuff,"20");
  123.       }
  124.    Pict->Tics->NX = Gadget17SInfo.LongInt;
  125.    Pict->Tics->NY = Gadget17aSInfo.LongInt;
  126.  
  127.    if (PlotPrefs==DEFAULT) {
  128.       Plot = Pict->Plot;
  129.       i = 0;
  130.       while (Plot) {
  131.          Plot->Enabled = TRUE;
  132.          Plot->Color = PLOTCOLORBASE + i;
  133.          Plot->PointType = PointType;
  134.          if (PointType>1) PointType = PointType-1;
  135.          else PointType = 6;
  136.          if (PlotType==LINEPLOT) Plot->PointSize = 0;
  137.          else Plot->PointSize = DEFAULT_POINT_SIZE;
  138.          if (PlotType==POINTPLOT) Plot->Lines=FALSE;
  139.          else Plot->Lines=TRUE;
  140.          if (Plot->Continued) {
  141.             Plot->NextPlot->Color = Plot->Color;
  142.             Plot->NextPlot->PointSize = Plot->PointSize;
  143.             Plot->NextPlot->Lines = Plot->Lines;
  144.             Plot->NextPlot->Enabled = Plot->Enabled;
  145.          }
  146.          Plot = Plot->NextPlot;
  147.          i++;
  148.       }
  149.    }
  150.  
  151.    else
  152.     {            /* GET USER'S INSTRUCTIONS FOR EACH PLOT */
  153.       Plot = Pict->Plot;
  154.  
  155.       for(i=0;i<Pict->NPlt;i++) {
  156.         j=min(19,i);
  157.         IText16.IText=SetText[j];
  158.         NewFrontWindow.Title = title1;
  159.         NewFrontWindow.FirstGadget = &Gadget43;
  160.         NewFrontWindow.Screen = screen;
  161.         if (!(FrontWindow = (struct Window *)OpenWindow(&NewFrontWindow)))
  162.          {
  163.             ErrorAlert(0);
  164.             CloseScreen(screen);
  165.             sexit(FALSE);
  166.          }
  167.         p = FrontWindow->RPort;
  168.         PrintIText(p,&IText16,0,0);
  169.         Move(p,336,76);
  170.         PolyDraw(p,5,border);
  171.         switch (PointType) {
  172.                   case 6:  GadMXSel(FrontWindow,&GadgPoint6,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  173.                            break;
  174.                   case 5:  GadMXSel(FrontWindow,&GadgPoint5,&GadgPoint6,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  175.                            break;
  176.                   case 4:  GadMXSel(FrontWindow,&GadgPoint4,&GadgPoint5,&GadgPoint6,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  177.                            break;
  178.                   case 3:  GadMXSel(FrontWindow,&GadgPoint3,&GadgPoint5,&GadgPoint4,&GadgPoint6,&GadgPoint2,&GadgPoint1);
  179.                            break;
  180.                   case 2:  GadMXSel(FrontWindow,&GadgPoint2,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint6,&GadgPoint1);
  181.                            break;
  182.                   case 1:  GadMXSel(FrontWindow,&GadgPoint1,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint6);
  183.                            break;
  184.                   default: PointType=6;
  185.                            GadMXSel(FrontWindow,&GadgPoint6,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  186.                            break;
  187.                   }
  188.  
  189.         QuitFrontFlag=GO;
  190.         SkipPlot=FALSE;
  191.         StopPlot=FALSE;
  192.  
  193.         while (QuitFrontFlag !=STOP)
  194.          {
  195.             Wait(1l<<FrontWindow->UserPort->mp_SigBit);        /* wait for a message */
  196.             while (p_message = (struct IntuiMessage *)GetMsg(FrontWindow->UserPort))
  197.               ProcCustMes(p_message,Pict);
  198.  
  199.          }
  200.  
  201.          if (SkipPlot) { Plot->Enabled = FALSE; SkipPlot=FALSE; }
  202.          else if (StopPlot)
  203.            {
  204.              StopPlot=FALSE;
  205.              i=Pict->NPlt;
  206.            }
  207.          else
  208.            {
  209.               Plot->Enabled = TRUE;
  210.               Plot->PointType=PointType;
  211.  
  212.               if (Colour==DEFAULT) Plot->Color = PLOTCOLORBASE + i;
  213.               else Plot->Color = Colour2.PlaneOnOff;
  214.  
  215.               if (PlotType==LINEPLOT) Plot->PointSize = 0;
  216.               else Plot->PointSize = Gadget46SInfo.LongInt;
  217.  
  218.               if (PlotType==POINTPLOT) Plot->Lines = FALSE;
  219.               else Plot->Lines = TRUE;
  220.            }
  221.  
  222.          if (Plot->Continued) {
  223.             Plot->NextPlot->Color = Plot->Color;
  224.             Plot->NextPlot->PointSize = Plot->PointSize;
  225.             Plot->NextPlot->Lines = Plot->Lines;
  226.             Plot->NextPlot->Enabled = Plot->Enabled;
  227.          }
  228.          Plot = Plot->NextPlot;
  229.          CloseWindow(FrontWindow);
  230.       }
  231.    }
  232. }
  233.  
  234.  
  235. void ProcHowMes(p_message,Pict)
  236. struct IntuiMessage *p_message;
  237. struct Pict *Pict;
  238.  
  239. {
  240. ULONG MesClass;        /*     Fields for storing      */
  241. USHORT MesCode;        /*     intuimessage data       */
  242. APTR Pointer;          /*                             */
  243. void HandleHowEvent();
  244.  
  245.    MesClass = p_message->Class;             /* Store values */
  246.    MesCode = p_message->Code;
  247.    Pointer = p_message->IAddress;
  248.    ReplyMsg(p_message);                     /* Reply to message */
  249.    HandleHowEvent(MesClass,MesCode,Pointer,Pict);
  250. }
  251.  
  252. void ProcCustMes(p_message,Pict)
  253. struct IntuiMessage *p_message;
  254. struct Pict *Pict;
  255.  
  256. {
  257. ULONG MesClass;        /*     Fields for storing      */
  258. USHORT MesCode;        /*     intuimessage data       */
  259. APTR Pointer;          /*                             */
  260. void HandleCustEvent();
  261.  
  262.    MesClass = p_message->Class;             /* Store values */
  263.    MesCode = p_message->Code;
  264.    Pointer = p_message->IAddress;
  265.    ReplyMsg(p_message);                     /* Reply to message */
  266.    HandleCustEvent(MesClass,MesCode,Pointer,Pict);
  267. }
  268.  
  269.  
  270. void HandleHowEvent(MesClass,MesCode,Pointer,Pict)
  271. struct Pict *Pict;
  272.  
  273. ULONG MesClass;        /*     Fields for storing      */
  274. USHORT MesCode;        /*     intuimessage data       */
  275. APTR Pointer;          /*                             */
  276. {
  277.  
  278.   if ( MesClass == GADGETDOWN)
  279.     {
  280.  
  281.       if (Pointer == (APTR)&Gadget13)  QuitFrontFlag = STOP;
  282.       if (Pointer == (APTR)&Gadget14)
  283.           {
  284.             if (Gadget14.Flags & SELECTED) Pict->ShowErr = FALSE;
  285.             else  Pict->ShowErr = Pict->ErrBar;
  286.           }
  287.       if (Pointer == (APTR)&Gadget15)
  288.           {
  289.             if (Pict->Grid==TRUE) Pict->Grid=FALSE;
  290.             else Pict->Grid=TRUE;
  291.           }
  292.       if (Pointer == (APTR)&Gadget16)
  293.           {
  294.             RemoveGadget(FrontWindow,&Gadget16);
  295.             if (PlotType==LINEPLOT)
  296.               {
  297.                   PlotType=POINTPLOT;
  298.                   Gadget16.GadgetRender = (APTR)&Image6b;
  299.               }
  300.             else if (PlotType==POINTPLOT)
  301.  
  302.               {
  303.                   PlotType=BOTHPLOT;
  304.                   Gadget16.GadgetRender = (APTR)&Image6c;
  305.               }
  306.             else
  307.               {
  308.                   PlotType=LINEPLOT;
  309.                   Gadget16.GadgetRender = (APTR)&Image6a;
  310.  
  311.               }
  312.             AddGadget(FrontWindow,&Gadget16,-1L);
  313.             RefreshGadgets(&Gadget16,FrontWindow,NULL);
  314.           }
  315.       if (Pointer == (APTR)&Gadget18)
  316.           {
  317.             if (PlotPrefs==DEFAULT) PlotPrefs=CHOOSE;
  318.             else PlotPrefs=DEFAULT;
  319.           }
  320.       else ;
  321.     }
  322.   if ( MesClass == RAWKEY)
  323.     {
  324.       if (MesCode ==196)  /* RETURN key RELEASED */
  325.          {
  326.             QuitFrontFlag = STOP;
  327.          }
  328.       else ;
  329.     }
  330.   else ;
  331. }
  332.  
  333. void HandleCustEvent(MesClass,MesCode,Pointer,Pict)
  334. struct Pict *Pict;
  335.  
  336. ULONG MesClass;        /*     Fields for storing      */
  337. USHORT MesCode;        /*     intuimessage data       */
  338. APTR Pointer;          /*                             */
  339. {
  340.  
  341.    if ( MesClass == GADGETDOWN)
  342.      {
  343.         if (Pointer == (APTR)&Gadget45)
  344.           {
  345.             RemoveGadget(FrontWindow,&Gadget45);
  346.             if (Gadget45.GadgetRender == (APTR)&Colour1)
  347.               {
  348.                 Colour=CHOOSE;
  349.                 Colour2.PlaneOnOff = 0x4;
  350.                 Gadget45.GadgetRender = (APTR)&Colour2;
  351.               }
  352.             else if (Colour2.PlaneOnOff==0xD)
  353.               {
  354.                 Colour=DEFAULT;
  355.                 Colour2.PlaneOnOff=0x4;
  356.                 Gadget45.GadgetRender = (APTR)&Colour1;
  357.               }
  358.             else Colour2.PlaneOnOff++;
  359.             AddGadget(FrontWindow,&Gadget45,-1L);
  360.             RefreshGadgets(&Gadget45,FrontWindow,NULL);
  361.           }
  362.         else if (Pointer == (APTR)&Gadget47)
  363.           {
  364.             RemoveGadget(FrontWindow,&Gadget47);
  365.             if (PlotType==LINEPLOT)
  366.               {
  367.                   PlotType=POINTPLOT;
  368.                   Gadget47.GadgetRender = (APTR)&Image6b;
  369.               }
  370.             else if (PlotType==POINTPLOT)
  371.  
  372.               {
  373.                   PlotType=BOTHPLOT;
  374.                   Gadget47.GadgetRender = (APTR)&Image6c;
  375.               }
  376.             else
  377.               {
  378.                   PlotType=LINEPLOT;
  379.                   Gadget47.GadgetRender = (APTR)&Image6a;
  380.               }
  381.             AddGadget(FrontWindow,&Gadget47,-1L);
  382.             RefreshGadgets(&Gadget47,FrontWindow,NULL);
  383.           }
  384.         else if (Pointer == (APTR)&GadgPoint6)
  385.           {
  386.               GadMXSel(FrontWindow,&GadgPoint6,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  387.               PointType=6;
  388.           }
  389.         else if (Pointer == (APTR)&GadgPoint5)
  390.           {
  391.               GadMXSel(FrontWindow,&GadgPoint5,&GadgPoint6,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  392.               PointType=5;
  393.           }
  394.         else if (Pointer == (APTR)&GadgPoint4)
  395.           {
  396.               GadMXSel(FrontWindow,&GadgPoint4,&GadgPoint5,&GadgPoint6,&GadgPoint3,&GadgPoint2,&GadgPoint1);
  397.               PointType=4;
  398.           }
  399.         else if (Pointer == (APTR)&GadgPoint3)
  400.           {
  401.               GadMXSel(FrontWindow,&GadgPoint3,&GadgPoint5,&GadgPoint4,&GadgPoint6,&GadgPoint2,&GadgPoint1);
  402.               PointType=3;
  403.           }
  404.         else if (Pointer == (APTR)&GadgPoint2)
  405.           {
  406.               GadMXSel(FrontWindow,&GadgPoint2,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint6,&GadgPoint1);
  407.               PointType=2;
  408.           }
  409.         else if (Pointer == (APTR)&GadgPoint1)
  410.           {
  411.               GadMXSel(FrontWindow,&GadgPoint1,&GadgPoint5,&GadgPoint4,&GadgPoint3,&GadgPoint2,&GadgPoint6);
  412.               PointType=1;
  413.           }
  414.         else if (Pointer == (APTR)&GadgetSkip)
  415.          {
  416.             QuitFrontFlag = STOP;
  417.             SkipPlot=TRUE;
  418.          }
  419.         else if (Pointer == (APTR)&GadgetStop)
  420.          {
  421.             QuitFrontFlag = STOP;
  422.             StopPlot=TRUE;
  423.          }
  424.  
  425.         else if (Pointer == (APTR)&Gadget43) QuitFrontFlag = STOP;
  426.         else ;
  427.      }
  428.    if ( MesClass == RAWKEY)
  429.      {
  430.       if (MesCode ==196)  /* RETURN key RELEASED */
  431.          {
  432.              QuitFrontFlag = STOP;
  433.          }
  434.       else ;
  435.      }
  436.    else ;
  437. }
  438.  
  439. /**
  440. *
  441. *   This routine selects gad1 and deselects the previously selected one.
  442. *   Maximum number of gadgets to be mutually excluded is six, obviously.
  443. *   Extension to more gadgets is obvious, too. This routine assumes that
  444. *   only one gadget is selected at a time.
  445. *
  446. **/
  447.  
  448. void GadMXSel(win,gad1,gad2,gad3,gad4,gad5,gad6)
  449. struct Window *win;
  450. struct Gadget *gad1,*gad2,*gad3,*gad4,*gad5,*gad6;
  451. {
  452. void GadMXSD();
  453. static struct Gadget *gadprev;
  454.  
  455.    gadprev = NULL;
  456.    if (gad1 != NULL)
  457.       if (gad1->Flags & SELECTED) return;
  458.    if (gad2 != NULL)
  459.       if (gad2->Flags & SELECTED) gadprev = gad2;
  460.    if (gad3 != NULL)
  461.       if (gad3->Flags & SELECTED) gadprev = gad3;
  462.    if (gad4 != NULL)
  463.       if (gad4->Flags & SELECTED) gadprev = gad4;
  464.    if (gad5 != NULL)
  465.       if (gad5->Flags & SELECTED) gadprev = gad5;
  466.    if (gad6 != NULL)
  467.       if (gad6->Flags & SELECTED) gadprev = gad6;
  468.  
  469.    GadMXSD(win,gad1,gadprev);
  470.  
  471.    return;
  472. }
  473.  
  474. /**
  475. *
  476. *   This routine selects gad1 and deselects gad2.
  477. *   Notice, that this version removes gadgets from the gadget list and adds
  478. *   them to the end. If you're sensitive to the location of the gadgets
  479. *   in the gadgetlist, you have to use: gadloc = RemoveGadget... and
  480. *   AddGadget(...,...,(long) gadloc), where gadloc is a USHORT. Then you
  481. *   have to refresh all gadgets to make sure the two you changed get
  482. *   refreshed.
  483. *
  484. **/
  485.  
  486. void GadMXSD(win,gad1,gad2)
  487. struct Window *win;
  488. struct Gadget *gad1,*gad2;
  489. {
  490. /*
  491. *   First select gad2 (yes!) and refresh.
  492. */
  493.    if (gad2 != NULL) {
  494.       RemoveGadget(win,gad2);
  495.       gad2->Flags |= SELECTED;
  496.       AddGadget(win,gad2,-1L);
  497.    }
  498.  
  499.    if (gad2 != NULL) RefreshGadgets(gad2,win,NULL);
  500. /*
  501. *   Now select gad1 and deselect gad2 and refresh.
  502. */
  503.    if (gad1 != NULL) {
  504.       RemoveGadget(win,gad1);
  505.       gad1->Flags |= SELECTED;
  506.       AddGadget(win,gad1,-1L);
  507.    }
  508.  
  509.    if (gad2 != NULL) {
  510.       RemoveGadget(win,gad2);
  511.       gad2->Flags &= ~SELECTED;
  512.       AddGadget(win,gad2,-1L);
  513.    }
  514.  
  515.    if (gad1 != NULL) RefreshGadgets(gad1,win,NULL);
  516.  
  517.    return;
  518. }
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.